#include <iostream>
#include <unistd.h>
#include <pthread.h>
#include <string>
#include <vector>

using namespace std;

class Task
{
public:
    Task() = default;
    Task(int x, int y):_x(x),_y(y)
    {

    }

    ~Task()
    {

    }

    int add()
    {
        return _x + _y;
    }

private:
    int _x;
    int _y;
    string _pthread_name;
};

class mypthread
{
public:
    mypthread() = default;
    
    mypthread(int x, int y,pthread_t id,string name):_task(x,y), _id(id), _pthread_name(name)
    {

    }

    ~mypthread()
    {

    }

    int task_run()
    {
        return _task.add();
    }

    void print()
    {
        cout << _pthread_name << " :task " << task_run() << endl;
    }
private:
    pthread_t _id;
    string _pthread_name;
    Task _task;
};


void* pthread_run(void* tmp)
{  
    int i = 0;
    while(i++)
    {
        if(i == 10)
        {
            break;
        }
        sleep(1);
        cout << "I am run" << endl;
    }
    return (void*)123;
}


void* pthreadrun(void* tmp)
{
    return nullptr;
}


int main()
{
    vector<mypthread*> v;
    for(int i = 0; i < 5 ; i++)
    {
        pthread_t tmp;
        pthread_create(&tmp,nullptr,pthreadrun,nullptr);
        mypthread* p = new mypthread(i,20,tmp,to_string(i) + "_pthread");
        v.push_back(p);
    }
    

    for(auto & e: v)
    {
        e->print();
    }
    return 0;
}